package com.qf.test;

import com.qf.entity.Users;
import com.qf.service.UsersService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 2019/9/28
 * Administrator
 * springdata0928
 * 面向对象面向君  不负代码不负卿
 */
public class Demo3 {
    public static void main(String[] args) {
        ApplicationContext applicationContext=
                new ClassPathXmlApplicationContext("spring-data.xml");

        UsersService  service = (UsersService)applicationContext.getBean("usersServiceImpl");

        //Users users = service.login("admin", "123");
        //System.out.println(users);
       /* List<Users> usersList = service.findByBirthdayBetween("2019-09-01", "2019-09-20");
        for (Users users : usersList) {
            System.out.println(users);
        }*/
      //  List<Users> usersList = service.findByUsernameLike("a");
     //   List<Users> usersList = service.findByUserIdIn(Arrays.asList(1,3,5),new Sort(Sort.Direction.DESC,"userId"));
       /* List list=new ArrayList();
        list.add(new Sort.Order(Sort.Direction.DESC,"userId"));
        list.add(new Sort.Order(Sort.Direction.ASC,"birthday"));
        List<Users> usersList = service.findByUserIdIn(Arrays.asList(1,3,5),new Sort(list));
         for (Users users : usersList) {
            System.out.println(users);
        }*/
        Page page = service.findByUsernameLike("%%", new PageRequest(0, 2,new Sort(Sort.Direction.DESC,"userId")));
        List<Users> content = page.getContent();
        System.out.println("当前页码值:"+page.getNumber());
        for (Users users : content) {
            System.out.println(users);
        }
        System.out.println("count="+service.countByUsernameContaining("a"));
    }
}
